<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>聊天室首页</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        body {
            background-color: #f0f7ff;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            color: #2c3e50;
        }

        .main-container {
            max-width: 900px;
            margin: 0 auto;
            padding: 2rem;
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
            margin-top: 3rem;
        }

        .welcome-header {
            color: #3182ce;
            font-weight: 600;
            border-bottom: 2px solid #e6f0ff;
            padding-bottom: 0.75rem;
            margin-bottom: 1.5rem;
            text-align: center; /* 添加文本居中 */
        }

        .welcome-text {
            color: #4a5568;
            margin-bottom: 1.5rem;
        }

        .btn-create {
            background-color: #3182ce;
            border: none;
            padding: 0.5rem 1rem;
            font-weight: 500;
        }

        .btn-create:hover {
            background-color: #2b6cb0;
        }

        .room-header {
            color: #3182ce;
            font-size: 1.25rem;
            margin-top: 2rem;
            margin-bottom: 1rem;
            font-weight: 600;
        }

        .room-list {
            border-radius: 6px;
            overflow: hidden;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
        }

        .room-item {
            border-left: 3px solid #3182ce;
            transition: all 0.2s;
        }

        .room-item:hover {
            background-color: #f0f7ff;
        }

        .room-link {
            color: #3182ce;
            text-decoration: none;
            display: block;
            padding: 0.5rem 0;
        }

        .room-link:hover {
            color: #2b6cb0;
        }

        .modal-header {
            background-color: #3182ce;
            color: white;
        }

        .modal-title {
            font-weight: 600;
        }

        .form-label {
            color: #4a5568;
            font-weight: 500;
        }

        .btn-modal-create {
            background-color: #3182ce;
            border: none;
        }

        .btn-modal-create:hover {
            background-color: #2b6cb0;
        }

        .empty-rooms {
            padding: 2rem;
            text-align: center;
            background-color: #f8fafc;
            border-radius: 6px;
            color: #718096;
        }

        .icon-margin {
            margin-right: 0.5rem;
        }
    </style>
</head>
<body>
<div class="container main-container">
    <h1 class="welcome-header">
        <i class="fas fa-comments icon-margin"></i>
        欢迎， <span th:text="${user.username}">用户</span>
    </h1>
    <p class="welcome-text text-center">选择一个现有聊天室或创建一个新的聊天室</p>

    <!-- 创建聊天室按钮 -->
    <div class="text-center mb-4">
        <button class="btn btn-create text-white" data-bs-toggle="modal" data-bs-target="#createRoomModal">
            <i class="fas fa-plus-circle icon-margin"></i>创建聊天室
        </button>
    </div>

    <!-- 显示聊天室列表 -->
    <div>
        <h3 class="room-header">
            <i class="fas fa-list icon-margin"></i>现有聊天室
        </h3>

        <div th:if="${#lists.isEmpty(rooms)}" class="empty-rooms">
            <i class="fas fa-info-circle icon-margin"></i>目前没有可用的聊天室
        </div>

        <ul class="list-group room-list" th:unless="${#lists.isEmpty(rooms)}">
            <li class="list-group-item room-item" th:each="room : ${rooms}">
                <a th:href="@{'/chat/' + ${room.id}}" class="room-link">
                    <i class="fas fa-comments icon-margin"></i>
                    <span th:text="${room.name}">聊天室名称</span>
                </a>
            </li>
        </ul>
    </div>
</div>

<!-- 创建聊天室的模态框 -->
<div class="modal fade" id="createRoomModal" tabindex="-1" aria-labelledby="createRoomModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="createRoomModalLabel">
                    <i class="fas fa-plus-circle icon-margin"></i>创建聊天室
                </h5>
                <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <form th:action="@{/create-room}" method="post">
                    <div class="mb-3">
                        <label for="roomName" class="form-label">聊天室名称</label>
                        <input type="text" id="roomName" name="name" class="form-control" required
                               placeholder="请输入聊天室名称">
                    </div>

                    <button type="submit" class="btn btn-modal-create text-white">
                        <i class="fas fa-check icon-margin"></i>创建聊天室
                    </button>
                </form>
            </div>
        </div>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>